< previous page page_165 next page >

Page 165
Loop While
Instead of checking the condition at the top of the loop, as you saw with the Do While loop, you can also test the condition at the bottom of the loop. In this example, youll put the Do statement at the top of the loop on a line by itself. You can then have one or many statements. To terminate the loop, you specify Loop While <Condition>. As long as the condition evaluates to a True value, execution will go back to the top of the loop and execute the statements again. When you use this format of looping, youre guaranteed that the code inside the loop will be executed one time. Heres the syntax:
9f31265bb40b592b1929e18a47ab28e5.gif
Do
    <Statement Block>
Loop While <Cond>
The following example is from the Loop While command button.
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdLoopWhile_Click ()
   Dim intNumber As Integer

   Cls
   intNumber = 1
   Do
      Print intNumber
      intNumber = intNumber + 1
   Loop While intNumber < 10
End Sub
Do Until
A Do Until loop is very similar to the Do While loop, except youre executing the loop until a condition becomes True. It all depends on what type of logic you need to use to check the loop condition. Heres the syntax:
9f31265bb40b592b1929e18a47ab28e5.gif
Do Until <Cond>
    <Statement Block>
Loop
The following example is from the Do Until command button.
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdUntil_Click ()
   Dim intLoop As Integer

   Cls

 
< previous page page_165 next page >

If you like this book, buy it!